/*
 * Package: org.grassfield.common.license.util
 * FileName: StreamReaderThread.java
 *  
 * Created by pandian on Jan 28, 2011
 */
package util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

/**
 * The Class StreamReaderThread.
 */
public class StreamReaderThread implements Runnable{
	Logger logger = Logger.getLogger(StreamReaderThread.class);
	private InputStream inputStream;
	private List<String> result=new ArrayList<String>();

	/**
	 * Sets the input stream.
	 * 
	 * @param inputStream the new input stream
	 */
	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	/**
	 * Gets the result.
	 * 
	 * @return the result
	 */
	public List<String> getResult() {
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		InputStreamReader reader = new InputStreamReader(inputStream);
		BufferedReader br = new BufferedReader(reader);
		String line=null;
		try {
			while ((line=br.readLine())!=null){
				logger.info("Reader Line:"+line);
				result.add(line);
			}
			br.close();
			reader.close();
		} catch (IOException e) {
			logger.error("Error while reading stream", e);
		}
	}
}
